//
//  MYFontSizeViewCOntroller.m
//  奇闻
//
//  Created by 似水灵修 on 14-12-2.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYFontSizeViewCOntroller.h"
#import "MYBaseSetting.h"
#import "MYFontSizeTool.h"
@interface MYFontSizeViewCOntroller ()

//当前选中的MYCheakItem
@property (nonatomic, strong) MYCheakItem *seletedCheakItem;

@end
@implementation MYFontSizeViewCOntroller
- (void)loadView
{
    [super loadView];
    // 添加第0组
    [self setupGroup0];
}
- (void)setupGroup0
{
    MYCheakItem *big = [MYCheakItem itemWithTitle:@"大"];
    big.operateBlock = ^(MYSettingItem *item){
        [self seletedItem:item];
    };
    MYCheakItem *middle = [MYCheakItem itemWithTitle:@"中"];
    middle.operateBlock = ^(MYSettingItem *item){
        [self seletedItem:item];
    };
    MYCheakItem *small = [MYCheakItem itemWithTitle:@"小"];
    small.operateBlock = ^(MYSettingItem *item){
        [self seletedItem:item];
    };
    MYGroupItem *group = [[MYGroupItem alloc] init];
    group.items = @[big, middle, small];
    [self.gorups addObject:group];
    //默认初始选项
    [self seletedTitle:[MYFontSizeTool fontSize]];
}
//默认初始选项
- (void)seletedTitle:(NSString *)title
{
    for (MYGroupItem *group in self.gorups) {
        for (MYCheakItem *cheak in group.items) {
            if ([cheak.title isEqualToString:title]) {
                cheak.cheak = YES;
                self.seletedCheakItem = cheak;
                [self.tableView reloadData];
            }
        }
    }
}
- (void)seletedItem:(MYSettingItem *)item
{
    MYCheakItem *cheakItem = (MYCheakItem *)item;
    self.seletedCheakItem.cheak = NO;
    cheakItem.cheak = YES;
    self.seletedCheakItem = cheakItem;
    [MYFontSizeTool saveFontSize:item.title];
    [self.tableView reloadData];
    [[NSNotificationCenter defaultCenter] postNotificationName:MYFontSizeKey object:nil];
}
@end
